package jdk.thread;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;


/**
 * Thread线程只有在使用同步关键字synchronized时被阻塞，线程的状态才是BLOCKED，
 * 而使用Lock(AQS)被阻塞时状态是WAITING，因为AQS同步的本质是CAS操作，
 */
public class BlockStateTest {

    public static final Lock lock = new ReentrantLock();

    public static void main(String[] args) throws InterruptedException {
        synchronized (BlockStateTest.class){
            Thread t = new Bst();
            t.start();
            Thread.sleep(1000);
            System.out.println(t.getState());
        }

        lock.lock();
        Thread t2 = new Lst();
        t2.start();
        Thread.sleep(1000);
        System.out.println(t2.getState());
        lock.unlock();
    }
}

class Bst extends Thread{
    @Override
    public void run() {
        System.out.println("使用同步关键字。。。。。");
        synchronized (BlockStateTest.class){

        }
    }
}

class Lst extends Thread{
    @Override
    public void run() {
        System.out.println("使用AQS。。。。。");
        BlockStateTest.lock.lock();


    }
}
